package com.leeh.jsontest;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;
import java.util.Random;

/**
 * Created by Liheng on 2017-04-17.
 */

public class ListViewCourseInfoAdpter extends ArrayAdapter<ListViewCourseContent> {
    private Context context;
    private int resource;
    private List<ListViewCourseContent> courseInfoList;
    private Random  r;
    private int []textViewStyle = { R.drawable.style_textview1, R.drawable.style_textview2, R.drawable.style_textview3,
            R.drawable.style_textview4, R.drawable.style_textview5, R.drawable.style_textview6,
            R.drawable.style_textview7,};

    public ListViewCourseInfoAdpter(Context context, int resource, List<ListViewCourseContent> objects) {
        super(context, resource, objects);
        this.context = context;
        this.resource = resource;
        this.courseInfoList = objects;
        r = new Random();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView  = LayoutInflater.from(context).inflate(resource,null);
        convertView.setBackgroundResource(textViewStyle[r.nextInt(7)]);
        ListViewCourseContent content = courseInfoList.get(position);
        ((TextView)convertView.findViewById(R.id.number_textView)).setText(content.getNumber());
        ((TextView)convertView.findViewById(R.id.course_name_textView)).setText(content.getName());
        ((TextView)convertView.findViewById(R.id.grade_textView)).setText(content.getGrade());
        ((TextView)convertView.findViewById(R.id.teacher_textView)).setText(content.getTeacher());
        ((TextView)convertView.findViewById(R.id.course_number_textView)).setText(content.getCourseNumber());
        ((TextView)convertView.findViewById(R.id.person_count_textView)).setText(content.getPersonCount());
        ((TextView)convertView.findViewById(R.id.weekend_number_textView)).setText(content.getWeekendCount());
        ((TextView)convertView.findViewById(R.id.time_textView)).setText(content.getTime());
        ((TextView)convertView.findViewById(R.id.address_textView)).setText(content.getAddress());

        return convertView;
    }
}
